package com.lmy.springboot.controller;

import com.lmy.springboot.bean.Furn;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class DruidSqlController {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @ResponseBody
    @GetMapping(value = "/sql")
    public List<Furn> crudDb() {
        BeanPropertyRowMapper<Furn> furnBeanPropertyRowMapper = new BeanPropertyRowMapper<>(Furn.class);
        List<Furn> furnList = jdbcTemplate.query("select * from furn", furnBeanPropertyRowMapper);
        for (Furn furn : furnList) {
            System.out.println(furn);
        }
        return furnList;
    }
}
